package com.base.myproject.client.HR.Self;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.LasyObejct;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseGrid;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.Widget;

public class SelfBcode_Train extends LayoutContainer implements LasyObejct {

	BaseStore<BusiObject> mainstore = null;
	public SelfBcode_Train(BaseStore<BusiObject> mainstore) {
		this.mainstore = mainstore;
		init();
		this.setStyleAttribute("background-color", "#DFE8F6");
	}
	void init() {
		initwidget();
	}
	Widget initwidget() {
		FieldSet fs1 = new FieldSet();
		fs1.add(createGrid());
		fs1.setHeading("已参加的培训");
		
		FieldSet fs2 = new FieldSet();
		fs2.add(create_noGrid());
		fs2.setHeading("未参加的培训");
		
		VerticalPanel v = new VerticalPanel();
		v.add(fs1);
		v.add(fs2);
		this.add(v);
		return null;
	}
	/******/
	BaseStore<BusiObject> store = null;
	BaseStore<BusiObject> getStore(){
	if(store==null) 
	{
		createStore();
	}
	return store;}
	BaseStore<BusiObject> createStore(){
	ModelType type = new ModelType();
	type.setRoot("records");
	type.setRecordName("record");
	type.setTotalName("totle");
	type.addField("icode");
	type.getField("icode").setType(Long.class);
	type.addField("bcode");
	type.getField("bcode").setType(String.class);
	type.addField("trainPlanNo");
	type.getField("trainPlanNo").setType(String.class);
	type.addField("trainName");
	type.getField("trainName").setType(String.class);
	type.addField("type");
	type.getField("type").setType(String.class);
	type.addField("quality");
	type.getField("quality").setType(String.class);
	type.addField("number");
	type.getField("number").setType(Integer.class);
	type.addField("date");
	type.getField("date").setType(Date.class);
	type.addField("period");
	type.getField("period").setType(Integer.class);
	type.addField("teacher");
	type.getField("teacher").setType(String.class);
	type.addField("status");
	type.getField("status").setType(String.class);
	type.addField("docName");
	type.getField("docName").setType(String.class);
	StoreInfo info = new StoreInfo();
	info.setTablename("hr_trainingRecord");
	info.setKeyname(new String[] { "icode" });
	info
			.setSql("select * from hr_trainingRecord where status=1 and bcode='{bcode}'");
	info.setParent(mainstore);// 关联主表
	info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
	info.setLinkparent_chile_columns(new String[] { "bcode" });// 关联主表字段
	  store = new BaseStore<BusiObject>(type, info);
	 return store;}
	
	BaseStore<BusiObject> store_no = null;
	BaseStore<BusiObject> get_noStore(){
	if(store_no==null) 
	{
		create_noStore();
	}
	return store_no;}
	BaseStore<BusiObject> create_noStore(){
	ModelType type = new ModelType();
	type.setRoot("records");
	type.setRecordName("record");
	type.setTotalName("totle");
	type.addField("icode");
	type.getField("icode").setType(Long.class);
	type.addField("bcode");
	type.getField("bcode").setType(String.class);
	type.addField("trainPlanNo");
	type.getField("trainPlanNo").setType(String.class);
	type.addField("trainName");
	type.getField("trainName").setType(String.class);
	type.addField("type");
	type.getField("type").setType(String.class);
	type.addField("quality");
	type.getField("quality").setType(String.class);
	type.addField("number");
	type.getField("number").setType(Integer.class);
	type.addField("date");
	type.getField("date").setType(Date.class);
	type.addField("period");
	type.getField("period").setType(Integer.class);
	type.addField("teacher");
	type.getField("teacher").setType(String.class);
	type.addField("status");
	type.getField("status").setType(String.class);
	type.addField("docName");
	type.getField("docName").setType(String.class);
	StoreInfo info = new StoreInfo();
	info.setTablename("hr_trainingRecord");
	info.setKeyname(new String[] { "icode" });
	info
			.setSql("select * from hr_trainingRecord where status=2 and bcode='{bcode}'");
	info.setParent(mainstore);// 关联主表
	info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
	info.setLinkparent_chile_columns(new String[] { "bcode" });// 关联主表字段
	store_no = new BaseStore<BusiObject>(type, info);
	 return store_no;
	}
	/********/
	BaseGrid grid=null;
	public BaseGrid createGrid(){
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
	
		ColumnConfig C3 = new ColumnConfig("trainPlanNo", "培训计划号", 80);
		TextField<String> t3 = new TextField<String>();
		t3.setName("trainPlanNo");
		columns.add(C3);
		
		ColumnConfig C4 = new ColumnConfig("trainName", "培训名称", 80);
		TextField<String> t4 = new TextField<String>();
		t4.setName("trainName");
		columns.add(C4);
		
		ColumnConfig C5 = new ColumnConfig("type", "培训类型", 80);
		TextField<String> t5 = new TextField<String>();
		t5.setName("type");
		columns.add(C5);
		
		ColumnConfig C6 = new ColumnConfig("quality", "培训性质", 80);
		TextField<String> t6 = new TextField<String>();
		t6.setName("quality");
		columns.add(C6);
		
		ColumnConfig C7 = new ColumnConfig("number", "培训期数", 80);
		TextField<String> t7 = new TextField<String>();
		t7.setName("number");
		columns.add(C7);
		
		ColumnConfig C8 = new ColumnConfig("date", "培训日期", 80);
		DateField dateField3 = new DateField();  
	    dateField3.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));  
	    C8.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C8);
		
		ColumnConfig C9 = new ColumnConfig("period", "时长", 30);
		TextField<String> t9= new TextField<String>();
		t9.setName("period");
		columns.add(C9);
		
		ColumnConfig C10 = new ColumnConfig("teacher", "讲师", 80);
		TextField<String> t10= new TextField<String>();
		t10.setName("teacher");
		columns.add(C10);
		
		ColumnConfig C11 = new ColumnConfig("status", "状态", 50);
		TextField<String> t11= new TextField<String>();
		t11.setName("status");
		columns.add(C11);
		
		ColumnConfig C12 = new ColumnConfig("docName", "证书扫描", 80);
		TextField<String> t12= new TextField<String>();
		t12.setName("status");
		columns.add(C12);
	
		ColumnModel cm = new ColumnModel(columns);
		grid = new BaseGrid(getStore(), cm,false,false);
		grid.setHeight(180);
		return grid ;
	}
	/****/
	
	BaseGrid grid_no = null;
	public BaseGrid create_noGrid(){
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		
		ColumnConfig C3 = new ColumnConfig("trainPlanNo", "培训计划号", 80);
		TextField<String> t3 = new TextField<String>();
		t3.setName("trainPlanNo");
		columns.add(C3);
		
		ColumnConfig C4 = new ColumnConfig("trainName", "培训名称", 80);
		TextField<String> t4 = new TextField<String>();
		t4.setName("trainName");
		columns.add(C4);
		
		ColumnConfig C5 = new ColumnConfig("type", "培训类型", 80);
		TextField<String> t5 = new TextField<String>();
		t5.setName("type");
		columns.add(C5);
		
		ColumnConfig C6 = new ColumnConfig("quality", "培训性质", 80);
		TextField<String> t6 = new TextField<String>();
		t6.setName("quality");
		columns.add(C6);
		
		ColumnConfig C7 = new ColumnConfig("number", "培训期数", 80);
		TextField<String> t7 = new TextField<String>();
		t7.setName("number");
		columns.add(C7);
		
		ColumnConfig C8 = new ColumnConfig("date", "培训日期", 80);
		DateField dateField3 = new DateField();  
	    dateField3.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));  
	    C8.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C8);
		
		ColumnConfig C9 = new ColumnConfig("period", "时长", 30);
		TextField<String> t9= new TextField<String>();
		t9.setName("period");
		columns.add(C9);
		
		ColumnConfig C10 = new ColumnConfig("teacher", "讲师", 80);
		TextField<String> t10= new TextField<String>();
		t10.setName("teacher");
		columns.add(C10);
		
		ColumnConfig C11 = new ColumnConfig("status", "状态", 50);
		TextField<String> t11= new TextField<String>();
		t11.setName("status");
		columns.add(C11);
		
		ColumnConfig C12 = new ColumnConfig("docName", "证书扫描", 80);
		TextField<String> t12= new TextField<String>();
		t12.setName("status");
		columns.add(C12);
	
		ColumnModel cm = new ColumnModel(columns);
		grid_no = new BaseGrid(get_noStore(), cm,false,false);
		grid_no.setHeight(150);
		return grid_no ;
	}

	@Override
	public boolean isopen() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean open() {
		// TODO Auto-generated method stub
		return false;
	}

}
